<template>
  <div>
    <div class="telnum">
        <van-cell-group border>
        <van-field v-model="password" label="密码" placeholder="请输入密码" autofocus/>
        </van-cell-group>
    </div>
     <div class="register">
        <van-button round type="danger" size="large" :disabled='flag' @click="MyRegister">完成</van-button>
      </div>
  </div>
</template>

<script>
import { toRegister } from "../../api/user";
export default {
    data () {
        return {
            password: '',
        }
    },
    computed: {
        flag() {
        // 满足输入的内容符合密码的规则
        if(/^\S*(?=\S{6,})(?=\S*\d)(?=\S*[A-Z])(?=\S*[a-z])\S*$/.test(this.password)) {
          return false;   //符合规则，按钮显示红色，表示可用
        } else {
          return true;    //不符合规则，按钮是淡红色，表示禁用
        }
      }
    },
    methods: {
      MyRegister() {
        toRegister({tel:localStorage.getItem('tel'),password:this.password}).then(res=>{
          console.log(res);
          this.$router.go(-3);
        })
      }
    }

}
</script>

<style scoped>
.register {
  width: 75%;
  margin: 30px auto;
}
</style>